package jdk8的特性.使用流来收集数据.常规分组;

import jdk8的特性.使用流来收集数据.MockTransaction;
import jdk8的特性.使用流来收集数据.Transaction;

import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.groupingBy;

/**
 * @author idea
 * @data 2018/9/16
 */
public class Test {

    public static void main(String[] args) {
        List<Transaction> transactionList=MockTransaction.mockTransactionList();
        Map<TransactionEnum,List<Transaction>> map=
                transactionList.stream().collect(
                        groupingBy(transaction->{
                              if(transaction.getTotalPrice()<=200) return TransactionEnum.LOW_PRIZE;
                                  else if(transaction.getTotalPrice()<=700) return TransactionEnum.NORMAL;
                                  else  return TransactionEnum.HIGH_PRIZE;
                        }
                ));
        for (TransactionEnum transactionEnum : map.keySet()) {
            System.out.println(map.get(transactionEnum));
            System.out.println(transactionEnum);
        }
    }

}
